window.addEventListener('load', function () { 
    var tel_reg = /^1[3|4|5|7|8]\d{9}$/;
    var qq_reg = /^[^0]\d{4,10}$/;
    // var nickname_reg = /^[a-zA-Z0-9_-]{6,16}$/;
    var nickname_reg = /^[\u4e00-\u9fa5]{2,8}$/;
    var code_reg = /^\d{6}$/;
    var password_reg = /^[a-zA-Z0-9_-]{6,16}$/;
    var tel = document.querySelector('#input_tel');
    var qqnum = document.querySelector('#qq_number');
    var nickname = document.querySelector('#nickname');
    var msgcode = document.querySelector('#msgcode');
    var password = document.querySelector('#input_password');
    var repassword = document.querySelector('#confr_pass');
    regexp(tel, tel_reg, '手机号');
    regexp(qqnum, qq_reg, 'QQ号码');
    regexp(nickname, nickname_reg, '昵称');
    regexp(msgcode, code_reg, '短信验证码');
    regexp(password, password_reg, '密码');

    function regexp(ele,reg,content) {
        ele.onblur = function () {
            if (reg.test(this.value)) {
                this.nextElementSibling.className = 'success';
                this.nextElementSibling.innerHTML = '<i class="success_icon"></i>';
            } else {
                this.nextElementSibling.className = 'error';
                this.nextElementSibling.innerHTML = '<i class="error_icon"></i> '+content+'格式不正确，请重新输入';
            }
        };
    }
    repassword.onblur = function () {
        if (this.value === password.value) {
            this.nextElementSibling.className = 'success';
            this.nextElementSibling.innerHTML = '<i class="success_icon"></i>';
        } else {
            this.nextElementSibling.className = 'error';
            this.nextElementSibling.innerHTML = '<i class="error_icon"></i> 密码不一致';
        }
    };
});